Passed
Push — master ( 222441...bcf585 )
by Jean
03:00
created

$.fn.enableNoUISlider   A

Complexity

Conditions 1
Paths 32

Size

Total Lines 42
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 26
nc 32
dl 0
loc 42
c 1
b 0
f 0
rs 9.256
nop 0

1 Function

Rating   Name   Duplication   Size   Complexity  
B 0 40 7
1
const $ = require('jquery'); // eslint-disable-line import/no-unresolved
2
const NoUISlider = require('nouislider');
3
const wNumb = require('wnumb');
4
5
$.fn.enableNoUISlider = function() {
6
    this.filter('input[type=range]:not(.js-nouislider-initialized)').each(function() {
7
        const $rangeInput = $(this);
8
9
        $rangeInput.css({display: 'none'}).addClass('js-nouislider-initialized');
10
11
        const $wrapper = $('<div class="nouislider-range-wrapper"><div></div></div>')
12
            .insertAfter($rangeInput);
13
14
        const min         = $rangeInput.attr('min')          ? Number($rangeInput.attr('min'))   : 0;
15
        const max         = $rangeInput.attr('max')          ? Number($rangeInput.attr('max'))   : 100;
16
        const step        = $rangeInput.attr('step')         ? Number($rangeInput.attr('step'))  : 1;
17
        const value       = $rangeInput.attr('value')        ? Number($rangeInput.attr('value')) : 1;
18
        const wnumbFormat = $rangeInput.data('wnumb-format') ? $rangeInput.data('wnumb-format')  : null;
19
20
        const options = {
21
            start: value, // [value, value2...]
22
            step,
23
            // connect: false,  // Display colored bars between handles
24
            range: {
25
                min,
26
                max,
27
            },
28
            tooltips: [true],
29
        };
30
31
        if (wnumbFormat !== null) {
32
            options.format = wNumb(wnumbFormat);
33
        }
34
35
        const noUiSliderInstance = NoUISlider.create($wrapper.find('div').get(0), options);
36
37
        $rangeInput.on('change', function () {
38
            noUiSliderInstance.set(this.value);
39
        });
40
41
        noUiSliderInstance.on('change', (values, handle, unencoded, tap, positions) => {
0 ignored issues
show
Unused Code introduced by
The parameter tap is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
Unused Code introduced by
The parameter positions is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
42
            $rangeInput.val(unencoded[0]).trigger('change');
43
            noUiSliderInstance.set(unencoded[0]);
44
        });
45
    });
46
};
47